/*
 * @Author: szx
 * @Date: 2021-11-06 13:23:32
 * @LastEditTime: 2021-11-06 13:27:16
 * @Description:
 * @FilePath: \leetcode\100-199\101\101.cpp
 */
#include <iostream>
#include <vector>
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right)
        : val(x), left(left), right(right) {}
};
class Solution {
   public:
    bool isSymmetric(TreeNode *root) { return check(root, root); }
    bool check(TreeNode *p, TreeNode *q) {
        if (!p && !q) return true;
        if (!p || !q) return false;
        return p->val == q->val && check(p->left, q->right) &&
               check(p->right, q->left);
    }
};